package hammersmith.local.ui.gui;

import hammersmith.local.exceptions.ArticleNotFoundException;
import hammersmith.local.exceptions.EmptyCartException;
import hammersmith.local.exceptions.StockTooLowException;
import hammersmith.local.exceptions.WrongMinCountException;
import hammersmith.local.management.ShopManagement;
import hammersmith.local.valueobjects.Article;
import hammersmith.local.valueobjects.Customer;
import hammersmith.local.valueobjects.Invoice;
import hammersmith.local.valueobjects.MassArticle;
import hammersmith.local.valueobjects.ShoppingCart;
import hammersmith.local.valueobjects.ShoppingCartTableRenderer;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Hashtable;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

public class CustomerMask extends JFrame {

	ShopManagement shop;
	Customer customer;
	private static final long serialVersionUID = 1L;
	private JPanel pnlHeader;
	private JPanel pnlContent;
	private JPanel pnlRight;
	private JPanel pnlLeft;
	private JPanel pnlBottom;
	private JPanel panel;
	private JScrollPane scrollPane;

	public CustomerMask(ShopManagement shop, Customer customer) {
		this.shop = shop;
		this.customer = customer;
		this.setSize(872, 694);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		pnlContent = new JPanel();
		panel = new JPanel();

		getContentPane().setBackground(Color.WHITE);
		getContentPane().setLayout(null);

		panel.setBounds(6, 6, 860, 660);
		getContentPane().add(panel);
		panel.setLayout(new BorderLayout(0, 0));

		renderPanelHeader();
		renderPanelLeft();
		renderPanelRight();
		renderPanelContent();

		pnlBottom = new JPanel();
		pnlBottom.setBackground(Color.WHITE);
		panel.add(pnlBottom, BorderLayout.SOUTH);
		pnlBottom.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 5));

		JLabel lblAgb = new JLabel("AGB");
		pnlBottom.add(lblAgb);

		JLabel lblKontakt = new JLabel("Kontakt");
		pnlBottom.add(lblKontakt);

		JLabel lblImpressum = new JLabel("Impressum");
		pnlBottom.add(lblImpressum);

		this.setVisible(true);

	}

	private void renderPanelHeader() {
		pnlHeader = new JPanel();
		pnlHeader.setBackground(Color.WHITE);
		pnlHeader.setBorder(BorderFactory.createLineBorder(Color.black));
		panel.add(pnlHeader, BorderLayout.NORTH);

		scrollPane = new JScrollPane();
		panel.add(scrollPane, BorderLayout.CENTER);

		JLabel lblPlaceholderLogo = new JLabel("");
		lblPlaceholderLogo.setIcon(new ImageIcon("img/logo.png"));
		pnlHeader.add(lblPlaceholderLogo);
	}

	private void renderPanelContent() {
		pnlContent.setMaximumSize(new Dimension(1, 32767));
		pnlContent.setAlignmentX(Component.RIGHT_ALIGNMENT);
		pnlContent.setBackground(Color.WHITE);

		scrollPane.setViewportView(pnlContent);
		GridBagLayout gbl_pnlContent = new GridBagLayout();
		gbl_pnlContent.columnWidths = new int[] { 508 };
		gbl_pnlContent.rowHeights = new int[] { 40, 0, 0, 0, 0, 0 };
		gbl_pnlContent.columnWeights = new double[] { 1.0 };
		gbl_pnlContent.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		pnlContent.setLayout(gbl_pnlContent);

		JLabel lblNewLabel = new JLabel("News");
		lblNewLabel.setFont(new Font("Dialog", Font.BOLD, 20));
		GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
		gbc_lblNewLabel.insets = new Insets(0, 0, 5, 0);
		gbc_lblNewLabel.gridx = 0;
		gbc_lblNewLabel.gridy = 0;
		pnlContent.add(lblNewLabel, gbc_lblNewLabel);

		JLabel lblNewsRead = new JLabel(
				shop.createNews("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."));
		GridBagConstraints gbc_lblLoremIpsumDolor = new GridBagConstraints();
		gbc_lblLoremIpsumDolor.insets = new Insets(0, 0, 5, 0);
		gbc_lblLoremIpsumDolor.gridx = 0;
		gbc_lblLoremIpsumDolor.gridy = 2;
		pnlContent.add(lblNewsRead, gbc_lblLoremIpsumDolor);
		scrollPane.setBorder(BorderFactory.createLineBorder(Color.black));
	}

	private void renderPanelLeft() {
		pnlLeft = new JPanel();
		pnlLeft.setBackground(Color.WHITE);
		panel.add(pnlLeft, BorderLayout.WEST);
		GridBagLayout gbl_pnlLeft = new GridBagLayout();
		gbl_pnlLeft.columnWidths = new int[] { 0, 0 };
		gbl_pnlLeft.rowHeights = new int[] { 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0,
				0, 0, 0 };
		gbl_pnlLeft.columnWeights = new double[] { 0.0, Double.MIN_VALUE };
		gbl_pnlLeft.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
				0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
		pnlLeft.setLayout(gbl_pnlLeft);
		pnlLeft.setBorder(BorderFactory.createLineBorder(Color.black));

		JLabel lblIndex = new JLabel("    News    ");
		lblIndex.setFont(new Font("Lucida Grande", Font.BOLD, 16));
		GridBagConstraints gbc_lblIndex = new GridBagConstraints();
		gbc_lblIndex.insets = new Insets(0, 0, 5, 0);
		gbc_lblIndex.gridx = 0;
		gbc_lblIndex.gridy = 1;
		pnlLeft.add(lblIndex, gbc_lblIndex);

		JLabel lblHauptseite = new JLabel("Hauptseite");
		lblHauptseite.setCursor(new Cursor(Cursor.HAND_CURSOR));
		GridBagConstraints gbc_lblHauptseite = new GridBagConstraints();
		gbc_lblHauptseite.insets = new Insets(0, 0, 5, 0);
		gbc_lblHauptseite.gridx = 0;
		gbc_lblHauptseite.gridy = 2;
		pnlLeft.add(lblHauptseite, gbc_lblHauptseite);
		pnlLeft.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				pnlContent.removeAll();
				renderPanelContent();
			}
		});

		JLabel lblSortiment = new JLabel("    Sortiment    ");
		lblSortiment.setFont(new Font("Lucida Grande", Font.BOLD, 16));
		GridBagConstraints gbc_lblSortiment = new GridBagConstraints();
		gbc_lblSortiment.insets = new Insets(0, 0, 5, 0);
		gbc_lblSortiment.gridx = 0;
		gbc_lblSortiment.gridy = 4;
		pnlLeft.add(lblSortiment, gbc_lblSortiment);

		JLabel lblTshirt = new JLabel("T-Shirts");
		GridBagConstraints gbc_test = new GridBagConstraints();
		gbc_test.insets = new Insets(0, 0, 5, 0);
		gbc_test.gridx = 0;
		gbc_test.gridy = 5;
		pnlLeft.add(lblTshirt, gbc_test);
		lblTshirt.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lblTshirt.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				pnlContent.removeAll();
				listArticles("T-Shirt");
				pnlContent.updateUI();
			}
		});

		JLabel lblHosen = new JLabel("Hosen");
		GridBagConstraints gbc_lblHosen = new GridBagConstraints();
		gbc_lblHosen.insets = new Insets(0, 0, 5, 0);
		gbc_lblHosen.gridx = 0;
		gbc_lblHosen.gridy = 6;
		pnlLeft.add(lblHosen, gbc_lblHosen);
		lblHosen.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lblHosen.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				pnlContent.removeAll();
				listArticles("Hose");
				pnlContent.updateUI();
			}
		});

		JLabel lblSweatshirts = new JLabel("Sweatshirts");
		GridBagConstraints gbc_lblSweatshirts = new GridBagConstraints();
		gbc_lblSweatshirts.insets = new Insets(0, 0, 5, 0);
		gbc_lblSweatshirts.gridx = 0;
		gbc_lblSweatshirts.gridy = 7;
		pnlLeft.add(lblSweatshirts, gbc_lblSweatshirts);
		lblSweatshirts.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lblSweatshirts.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				pnlContent.removeAll();
				listArticles("Sweatshirt");
				pnlContent.updateUI();
			}
		});

		JLabel lblJacken = new JLabel("Jacken");
		GridBagConstraints gbc_lblJacken = new GridBagConstraints();
		gbc_lblJacken.insets = new Insets(0, 0, 5, 0);
		gbc_lblJacken.gridx = 0;
		gbc_lblJacken.gridy = 8;
		pnlLeft.add(lblJacken, gbc_lblJacken);
		lblJacken.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lblJacken.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				pnlContent.removeAll();
				listArticles("Jacke");
				pnlContent.updateUI();
			}
		});

		JLabel lblHemden = new JLabel("Hemden");
		GridBagConstraints gbc_lblHemden = new GridBagConstraints();
		gbc_lblHemden.insets = new Insets(0, 0, 5, 0);
		gbc_lblHemden.gridx = 0;
		gbc_lblHemden.gridy = 9;
		pnlLeft.add(lblHemden, gbc_lblHemden);
		lblHemden.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lblHemden.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				pnlContent.removeAll();
				listArticles("Hemd");
				pnlContent.updateUI();
			}
		});

		JLabel lblBlusen = new JLabel("Blusen");
		GridBagConstraints gbc_lblBlusen = new GridBagConstraints();
		gbc_lblBlusen.insets = new Insets(0, 0, 5, 0);
		gbc_lblBlusen.gridx = 0;
		gbc_lblBlusen.gridy = 10;
		pnlLeft.add(lblBlusen, gbc_lblBlusen);
		lblBlusen.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lblBlusen.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				pnlContent.removeAll();
				listArticles("Bluse");
				pnlContent.updateUI();
			}
		});

		JLabel lblSchuhe = new JLabel("Schuhe");
		GridBagConstraints gbc_lblSchuhe = new GridBagConstraints();
		gbc_lblSchuhe.insets = new Insets(0, 0, 5, 0);
		gbc_lblSchuhe.gridx = 0;
		gbc_lblSchuhe.gridy = 11;
		pnlLeft.add(lblSchuhe, gbc_lblSchuhe);
		lblSchuhe.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lblSchuhe.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				pnlContent.removeAll();
				listArticles("Schuh");
				pnlContent.updateUI();
			}
		});

		JLabel lblAccessoires = new JLabel("Accessoires");
		GridBagConstraints gbc_lblAccessoires = new GridBagConstraints();
		gbc_lblAccessoires.gridx = 0;
		gbc_lblAccessoires.gridy = 12;
		pnlLeft.add(lblAccessoires, gbc_lblAccessoires);
		lblAccessoires.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lblAccessoires.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				pnlContent.removeAll();
				listArticles("Accessoire");
				pnlContent.updateUI();
			}
		});
	}

	private void renderPanelRight() {
		pnlRight = new JPanel();
		pnlRight.setBackground(Color.WHITE);
		panel.add(pnlRight, BorderLayout.EAST);
		GridBagLayout gbl_pnlRight = new GridBagLayout();
		gbl_pnlRight.columnWidths = new int[] { 0, 0 };
		gbl_pnlRight.rowHeights = new int[] { 43, 30, 0, 0, 0 };
		gbl_pnlRight.columnWeights = new double[] { 0.0, Double.MIN_VALUE };
		gbl_pnlRight.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		pnlRight.setLayout(gbl_pnlRight);
		pnlRight.setBorder(BorderFactory.createLineBorder(Color.black));

		JLabel lblLogout = new JLabel("Logout");
		lblLogout.setVerticalAlignment(SwingConstants.TOP);
		GridBagConstraints gbc_label = new GridBagConstraints();
		gbc_label.insets = new Insets(0, 0, 5, 0);
		gbc_label.gridx = 0;
		gbc_label.gridy = 0;
		pnlRight.add(lblLogout, gbc_label);
		lblLogout.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lblLogout.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				dispose();
				new LoginMask();
			}
		});

		JLabel lblWarenkorb = new JLabel("    Warenkorb    ");
		lblWarenkorb.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				pnlContent.removeAll();
				showShoppingCartContent();

			}
		});
		lblWarenkorb.setFont(new Font("Lucida Grande", Font.BOLD, 16));
		GridBagConstraints gbc_lblWarenkorb = new GridBagConstraints();
		gbc_lblWarenkorb.insets = new Insets(0, 0, 5, 0);
		gbc_lblWarenkorb.gridx = 0;
		gbc_lblWarenkorb.gridy = 1;
		pnlRight.add(lblWarenkorb, gbc_lblWarenkorb);

		JLabel lblArtikelIm = new JLabel("Artikel im");
		GridBagConstraints gbc_lblArtikelIm = new GridBagConstraints();
		gbc_lblArtikelIm.insets = new Insets(0, 0, 5, 0);
		gbc_lblArtikelIm.gridx = 0;
		gbc_lblArtikelIm.gridy = 2;
		pnlRight.add(lblArtikelIm, gbc_lblArtikelIm);

		int size = shop.getRefreshedCartCount(customer);

		JLabel lblArtikelImWarenkorb = new JLabel("Warenkorb: " + size);
		GridBagConstraints gbc_lblArtikelImWarenkorb = new GridBagConstraints();
		gbc_lblArtikelImWarenkorb.gridx = 0;
		gbc_lblArtikelImWarenkorb.gridy = 3;
		pnlRight.add(lblArtikelImWarenkorb, gbc_lblArtikelImWarenkorb);

	}

	public void listArticles(String type) {

		GridBagLayout gbl_pnlContent = new GridBagLayout();
		gbl_pnlContent.columnWidths = new int[] { 0, 0 };
		gbl_pnlContent.rowHeights = new int[] { 0, 0, 0, 10, 0, 0, 0, 0, 0, 0,
				0, 0, 0, 0 };
		gbl_pnlContent.columnWeights = new double[] { 0.0, 0.0,
				Double.MIN_VALUE };
		gbl_pnlContent.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		pnlContent.setLayout(gbl_pnlContent);

		Hashtable<String, ArrayList<String>> allArticleNamesByTypeWithSizeList = shop
				.getAllArticlesByType(type);

		int count = 0;
		int arrayCounter = 0;

		int size = allArticleNamesByTypeWithSizeList.keySet().size();
		final String[] nameArray = new String[size];
		final JComboBox[] sizeArray = new JComboBox[size];
		final JComboBox[] colorArray = new JComboBox[size];
		final JButton[] cartArray = new JButton[size];

		for (final String s : allArticleNamesByTypeWithSizeList.keySet()) {

			// Gibt das erste findbare Artikelobjekt mit dem Namen zurück
			Article article = shop.getArticleByName(s);

			// Größenarray vom aktuellen Key (aktueller Artiklename)
			ArrayList<String> sizeList = allArticleNamesByTypeWithSizeList
					.get(s);

			JLabel lblPic = new JLabel("");
			JLabel lblName = new JLabel("Name: " + s);

			JLabel lblDescription = new JLabel("Beschreibung: ");
			JLabel lblSize = new JLabel("Größe: ");
			JLabel lblColor = new JLabel("Farbe: ");
			JLabel lblPrice = new JLabel(" Preis: " + article.getPrice());
			JLabel lblLine = new JLabel(
					"<html>------------------------------------<br></html>");

			final JComboBox<String> cboxSize = new JComboBox<String>();
			final JComboBox<String> cboxColor = new JComboBox<String>();

			JButton btnCart = new JButton("In den Warenkorb");

			nameArray[arrayCounter] = s;
			sizeArray[arrayCounter] = cboxSize;
			colorArray[arrayCounter] = cboxColor;
			cartArray[arrayCounter] = btnCart;

			cboxSize.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {

					String size = cboxSize.getSelectedItem().toString();
					String name = s;
					ArrayList<String> colorList = shop
							.getAllColorsBySizeAndName(size, name);

					cboxColor.removeAllItems();
					for (String string : colorList) {
						cboxColor.addItem(string);
					}
				}
			});

			// Größen hinzufügen zur ComboBox!
			cboxSize.removeAllItems();
			for (String string : sizeList) {
				cboxSize.addItem(string);
			}

			btnCart.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {

					int place = 0;
					JButton source = (JButton) e.getSource();

					for (int i = 0; i < cartArray.length; i++) {
						if (cartArray[i] == source) {
							place = i;

							String name = nameArray[place];
							String size = sizeArray[place].getSelectedItem()
									.toString();
							String color = colorArray[place].getSelectedItem()
									.toString();

							Article article = shop
									.getArticleBySizeColorAndName(name, size,
											color);
							try {
								shop.addToCart(customer, article, 1);
								System.out.println(article.getName() + " "
										+ article.getSize() + " "
										+ article.getColor());

								pnlRight.removeAll();
								renderPanelRight();

							} catch (StockTooLowException e1) {
								// TODO Auto-generated catch block
								JOptionPane.showMessageDialog(null,
										e1.getMessage());
							} catch (WrongMinCountException e1) {
								// TODO Auto-generated catch block
								JOptionPane.showMessageDialog(null,
										e1.getMessage());
							}
							break;
						}
					}
				}
			});

			JPanel pnlInfo = new JPanel();
			pnlInfo.setBorder(BorderFactory.createLineBorder(Color.black));

			pnlInfo.add(lblName);
			pnlInfo.add(lblDescription);

			lblPic.setIcon(new ImageIcon("img/article.png"));

			// BILD
			GridBagConstraints gridPic = new GridBagConstraints();
			gridPic.gridwidth = 2;
			gridPic.anchor = GridBagConstraints.WEST;
			gridPic.insets = new Insets(5, 5, 5, 0);
			gridPic.gridx = 0;
			gridPic.gridy = count;
			pnlContent.add(lblPic, gridPic);

			// NAME
			GridBagConstraints gridName = new GridBagConstraints();
			gridName.gridwidth = 2;
			gridName.anchor = GridBagConstraints.WEST;
			gridName.insets = new Insets(5, 5, 5, 0);
			gridName.gridx = 0;
			gridName.gridy = count + 1;
			pnlContent.add(lblName, gridName);

			// BESCHREIBUNG
			GridBagConstraints gridDesc = new GridBagConstraints();
			gridDesc.gridwidth = 2;
			gridDesc.anchor = GridBagConstraints.WEST;
			gridDesc.insets = new Insets(5, 5, 5, 0);
			gridDesc.gridx = 0;
			gridDesc.gridy = count + 2;
			pnlContent.add(lblDescription, gridDesc);

			// BESCHREIBUNG-TEXTFELD
			final JTextArea txtDescription = new JTextArea(6, 6);
			txtDescription.setLineWrap(true);
			txtDescription.setWrapStyleWord(true);
			txtDescription.setText(article.getDescription());
			txtDescription.setBorder(new LineBorder(new Color(0, 0, 0)));
			txtDescription.setEditable(false);
			GridBagConstraints gridDescTxt = new GridBagConstraints();
			gridDescTxt.gridwidth = 2;
			gridDescTxt.anchor = GridBagConstraints.WEST;
			gridDescTxt.insets = new Insets(5, 5, 5, 0);
			gridDescTxt.fill = GridBagConstraints.BOTH;
			gridDescTxt.gridx = 0;
			gridDescTxt.gridy = count + 3;
			pnlContent.add(txtDescription, gridDescTxt);

			// GRÖßE
			GridBagConstraints gridSize = new GridBagConstraints();
			gridSize.gridwidth = 1;
			gridSize.anchor = GridBagConstraints.WEST;
			gridSize.insets = new Insets(5, 5, 5, 0);
			gridSize.gridx = 0;
			gridSize.gridy = count + 4;
			pnlContent.add(lblSize, gridSize);

			// GRÖßE-COMBOBOX
			GridBagConstraints gridComboSize = new GridBagConstraints();
			gridComboSize.gridwidth = 1;
			gridComboSize.anchor = GridBagConstraints.WEST;
			gridComboSize.insets = new Insets(5, 5, 5, 0);
			gridComboSize.gridx = 1;
			gridComboSize.gridy = count + 4;
			pnlContent.add(cboxSize, gridComboSize);

			// FARBE
			GridBagConstraints gridColor = new GridBagConstraints();
			gridColor.anchor = GridBagConstraints.WEST;
			gridColor.gridwidth = 1;
			gridColor.insets = new Insets(5, 5, 5, 0);
			gridColor.gridx = 0;
			gridColor.gridy = count + 5;
			pnlContent.add(lblColor, gridColor);

			// FARBE-COMBOBOX
			GridBagConstraints gridComboColor = new GridBagConstraints();
			gridComboColor.gridwidth = 1;
			gridComboColor.anchor = GridBagConstraints.WEST;
			gridComboColor.insets = new Insets(5, 5, 5, 0);
			gridComboColor.gridx = 1;
			gridComboColor.gridy = count + 5;
			pnlContent.add(cboxColor, gridComboColor);

			// PREIS
			GridBagConstraints gridPrice = new GridBagConstraints();
			gridPrice.gridwidth = 2;
			gridPrice.anchor = GridBagConstraints.WEST;
			gridPrice.insets = new Insets(5, 5, 5, 0);
			gridPrice.gridx = 0;
			gridPrice.gridy = count + 6;
			pnlContent.add(lblPrice, gridPrice);

			// IN DEN WARENKORB
			GridBagConstraints gridCart = new GridBagConstraints();
			gridCart.gridwidth = 2;
			gridCart.anchor = GridBagConstraints.WEST;
			gridCart.insets = new Insets(5, 5, 5, 0);
			gridCart.gridx = 0;
			gridCart.gridy = count + 7;
			pnlContent.add(btnCart, gridCart);

			// LINIE
			GridBagConstraints gridLine = new GridBagConstraints();
			gridLine.gridwidth = 2;
			gridLine.anchor = GridBagConstraints.WEST;
			gridLine.insets = new Insets(5, 5, 5, 0);
			gridLine.gridx = 0;
			gridLine.gridy = count + 8;
			pnlContent.add(lblLine, gridLine);

			count += 9;
			arrayCounter++;
		}
	}

	public void showShoppingCartContent() {
		pnlContent.removeAll();
		pnlContent.setLayout(null);

		final JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 11, 580, 425);
		pnlContent.add(scrollPane);

		final JTable table = new JTable();
		table.setAutoCreateRowSorter(true);
		
		DefaultTableModel model = new DefaultTableModel() {

			@Override
			public boolean isCellEditable(int row, int column) {
				return false;
			}
		};
		model.addColumn("Art.-Nr.");
		model.addColumn("Typ");
		model.addColumn("Name");
		model.addColumn("Größe");
		model.addColumn("Farbe");
		model.addColumn("Stückpreis");
		model.addColumn("Anzahl");
		model.addColumn("Preis in €");

		ShoppingCart cart = customer.getCart();

		Hashtable<Article, Integer> list = cart.getList();
		for (Article article : list.keySet()) {

			model.addRow(new Object[] { String.valueOf(article.getId()),
					article.getType(), article.getName(), article.getSize(),
					article.getColor(), String.valueOf(article.getPrice()),
					list.get(article).intValue(), String.valueOf(article.getPrice()*list.get(article).intValue()) });

		}
		
		table.setDefaultRenderer(Object.class, new ShoppingCartTableRenderer(cart));
		
		model.addRow(new Object[] { "","","","","","","",""});
		model.addRow(new Object[] { "","","","","","","Gesamt", cart.getShoppingCartFullCosts()});
		
		table.setModel(model);

		table.getColumnModel().getColumn(0).setResizable(false);
		table.getColumnModel().getColumn(0).setPreferredWidth(45);
		table.getColumnModel().getColumn(1).setResizable(false);
		table.getColumnModel().getColumn(1).setPreferredWidth(80);
		table.getColumnModel().getColumn(2).setResizable(false);
		table.getColumnModel().getColumn(2).setPreferredWidth(165);
		table.getColumnModel().getColumn(3).setResizable(false);
		table.getColumnModel().getColumn(3).setPreferredWidth(50);
		table.getColumnModel().getColumn(4).setResizable(false);
		table.getColumnModel().getColumn(4).setPreferredWidth(83);
		table.getColumnModel().getColumn(5).setResizable(false);
		table.getColumnModel().getColumn(5).setPreferredWidth(70);
		table.getColumnModel().getColumn(6).setResizable(false);
		table.getColumnModel().getColumn(6).setPreferredWidth(54);
		table.getColumnModel().getColumn(7).setResizable(false);
		table.getColumnModel().getColumn(7).setPreferredWidth(70);

		scrollPane.setViewportView(table);

		JPanel pnlButtons = new JPanel();
		pnlButtons.setAlignmentY(Component.BOTTOM_ALIGNMENT);
		pnlButtons.setBorder(new LineBorder(new Color(0, 0, 0)));
		pnlButtons.setBounds(10, 441, 580, 35);
		pnlContent.add(pnlButtons);

		JButton btnDelete = new JButton("Artikel entfernen");
		btnDelete.setActionCommand("New Command");
		btnDelete.setAlignmentY(Component.TOP_ALIGNMENT);
		pnlButtons.add(btnDelete);
		btnDelete.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {

				int row = table.getSelectedRow();
				String id = String.valueOf(table.getValueAt(row, 0));

				Article article = null;

				try {
					article = shop.getArticleManagement().getArticleById(
							Long.valueOf(id));

					shop.removeArticleFromCart(customer, article.getId());

				} catch (NumberFormatException e1) {
					JOptionPane.showMessageDialog(null, e1.getMessage());
				} catch (ArticleNotFoundException e1) {
					JOptionPane.showMessageDialog(null, e1.getMessage());
				} catch (EmptyCartException e1) {
					JOptionPane.showMessageDialog(null, e1.getMessage());
				}

				table.validate();
				renderPanelRight();
				showShoppingCartContent();

			}
		});

		JButton btnPlus = new JButton("+");
		JButton btnMinus = new JButton("-");
		pnlButtons.add(btnPlus);
		pnlButtons.add(btnMinus);

		btnPlus.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {

				int row = table.getSelectedRow();
				String id = String.valueOf(table.getValueAt(row, 0));
				String currentCount = String.valueOf(table.getValueAt(row, 6));

				Article article = null;

				try {
					article = shop.getArticleManagement().getArticleById(
							Long.valueOf(id));

					if (article instanceof MassArticle) {

						MassArticle mA = (MassArticle) article;
						shop.editCartStock(
								customer,
								article.getId(),
								Integer.valueOf(currentCount)
										+ mA.getMinCount());

					} else {
						shop.editCartStock(customer, article.getId(),
								Integer.valueOf(currentCount) + 1);
					}

					showShoppingCartContent();

				} catch (NumberFormatException e1) {
					JOptionPane.showMessageDialog(null, e1.getMessage());
				} catch (ArticleNotFoundException e1) {
					JOptionPane.showMessageDialog(null, e1.getMessage());
				} catch (WrongMinCountException e1) {
					JOptionPane.showMessageDialog(null, e1.getMessage());
				} catch (StockTooLowException e1) {
					JOptionPane.showMessageDialog(null, e1.getMessage());
				}

			}
		});

		btnMinus.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {

				int row = table.getSelectedRow();
				String id = String.valueOf(table.getValueAt(row, 0));
				String currentCount = String.valueOf(table.getValueAt(row, 6));

				Article article = null;

				try {
					article = shop.getArticleManagement().getArticleById(
							Long.valueOf(id));

					if (article instanceof MassArticle) {

						MassArticle mA = (MassArticle) article;
						if (Integer.parseInt(currentCount) == mA.getMinCount()) {
							shop.removeArticleFromCart(customer,
									article.getId());
						} else {
							shop.editCartStock(
									customer,
									article.getId(),
									Integer.valueOf(currentCount)
											- mA.getMinCount());
						}

					} else {
						if (Integer.parseInt(currentCount) == 1) {
							shop.removeArticleFromCart(customer,
									article.getId());
						} else {
							shop.editCartStock(customer, article.getId(),
									Integer.valueOf(currentCount) - 1);
						}
					}

					showShoppingCartContent();
					renderPanelRight();

				} catch (NumberFormatException e1) {
					JOptionPane.showMessageDialog(null, e1.getMessage());
				} catch (ArticleNotFoundException e1) {
					JOptionPane.showMessageDialog(null, e1.getMessage());
				} catch (WrongMinCountException e1) {
					JOptionPane.showMessageDialog(null, e1.getMessage());
				} catch (StockTooLowException e1) {
					JOptionPane.showMessageDialog(null, e1.getMessage());
				} catch (EmptyCartException e1) {
					JOptionPane.showMessageDialog(null, e1.getMessage());
				}

			}
		});

		JButton btnBuy = new JButton("Zur Kasse");
		pnlButtons.add(btnBuy);

		btnBuy.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {

				// ZUR KASSE GEHEN!
				try {

					Invoice invoice = shop.buy(customer);
					new InvoiceMask(invoice, customer);

					customer.getCart().clearCart();
					renderPanelRight();
					showShoppingCartContent();

				} catch (EmptyCartException e1) {
					JOptionPane.showMessageDialog(null, e1.getMessage());
				}

			}
		});

		pnlContent.add(pnlButtons);
		pnlContent.updateUI();

	}
}
